package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.OrderTimeReq;
import com.sbj.dto.res.OrderTimeRes;
import com.sbj.entity.OrderTime;
import com.sbj.service.OrderTimeService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/11 09:26
 */
@RestController
@RequestMapping(value = "/orderTime")
@AllArgsConstructor
public class OrderTimeController implements BaseCommonInterface<OrderTimeReq, OrderTimeRes> {

    private final OrderTimeService orderTimeService;

    @Override
    public Result<String> save(@Valid OrderTimeReq orderTimeReq) {
        orderTimeService.saveOrUpdate(Convert.convert(OrderTime.class, orderTimeReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        orderTimeService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<OrderTimeRes>> lists(OrderTimeReq orderTimeReq) {

        return Result.successResult(orderTimeService.lists(orderTimeReq));
    }

    @GetMapping(value = "/findOne")
    public Result<OrderTimeRes>  findOne(){

        return Result.successResult(orderTimeService.buyTime());
    }

    @Override
    public Result<OrderTimeRes> findById(Integer id) {
        return Result.successResult(Convert.convert(OrderTimeRes.class,orderTimeService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<OrderTimeRes> list) {
        return null;
    }
}
